package per.zqx.workQueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import per.zqx.utils.RabbitUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Producer
 *
 * @author Sa  2021-03-17 09:35
 */
public class Producer_RoundRobin {
    public static void main(String[] args) {
        final String QUEUE_NAME = "work_queue";
        try (Connection connection = RabbitUtils.getConnection();){
            Channel channel = connection.createChannel();
            channel.queueDeclare(QUEUE_NAME,true,false,false,null);
            for (int i = 0; i < 15; i++) {
                String msg = String.valueOf(i);
                channel.basicPublish("",QUEUE_NAME,null,msg.getBytes());
                System.out.println("Producer_fair sent a message : " + msg);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
    }
}
